package com.fantasy.regEx.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class 去掉特殊字符 {

	public static String StringFilter(String str) throws PatternSyntaxException {
		// 只允许字母和数字 // String regEx ="[^a-zA-Z0-9]";
		// 清除掉所有特殊字符
		String regEx = "[-_`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		return m.replaceAll("").trim();
	}
	public static String StringFilter1(String str) throws PatternSyntaxException {
		// 只允许字母和数字 // String regEx ="[^a-zA-Z0-9]";
		// 清除掉所有特殊字符
		String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		if(m.find()){
			m.group();
		}
		return "";
	}
	
	public static void main(String args[]){
		String str = "DL - (Model) - XX EPR Arrangement Notice";
		System.out.println(StringFilter(str).replace(" ", "").toUpperCase());
		str = "dl-model-xxeprarrangementnotice";
		System.out.println(StringFilter(str).replace(" ", "").toUpperCase());
		str = "DL - (Model) - XX EPR Arrangement Notice";
		System.out.println(StringFilter1(str));
	}
	
}
